package com.tul.exercise.base.java8.stream.base;

import com.tul.exercise.base.java8.common.Constant;
import com.tul.exercise.base.java8.util.BeanAtributeHelper;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author tuliang
 */
public class Person {
    /**
     * id
     */
    protected String id;

    /**
     * mingc
     */
    private String name;

    /**
     * 性别
     */
    private String sex;

    public Person() {
        this.id = UUID.randomUUID().toString().replaceAll("-", "");
        this.sex = BeanAtributeHelper.getRandomItem(Stream.of("w", "m")
                .collect(Collectors.toList()));
    }

    public Person(String name) {
        this.id = UUID.randomUUID().toString().replaceAll("-", "");
        this.name = name;
        this.sex = "w";
    }

    public Person(String name, String sex) {
        this.name = name;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

    public Boolean isMam() {
        return sex.equals("m");
    }

    /**
     * 创建Artist
     *
     * @return Artist
     */
    public static Person createPerson() {
        Person result = new Artist();
        result.setName(BeanAtributeHelper.getRandomItem(Constant.ARTIST_NAMES));
        return result;
    }

    /**
     * 创建Artist列表
     *
     * @param num 个数
     * @return List<Artist>
     */
    public static List<Person> createPersons(int num) {
        List<Person> list = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            list.add(createPerson());
        }
        return list;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
